package com.cloud.code.stream.taobao.shopex;

import org.apache.commons.lang3.StringUtils;
import org.junit.Before;
import org.junit.Test;

import java.util.Comparator;
import java.util.List;

public class MainTest {

    public static List<Goods> goods;

    @Before
    public void before() {
        goods = CartService.getGoods();
    }

    @Test
    public void filterTest() {
        //peek filter map
//        goods.stream().peek(tmp -> System.out.println(tmp.getName()))
//                .filter(goods1 -> goods1.getPrice() > 15)
//                .forEach(tem -> System.out.println(tem.getName() + tem.getPrice()));
//        goods.stream().filter(goods1 -> GoodsType.EAT.equals(goods1.getType()))
//                .map(Goods::getName).collect(Collectors.toList())
//                .forEach(System.out::println);
//        //分类groupBy
//        Map<GoodsType, List<Goods>> collect = goods.stream().distinct().collect(Collectors.groupingBy(Goods::getType));
//        System.out.println(JSON.toJSONString(collect , true));

        goods.stream().filter(goods1 -> StringUtils.isNotBlank(goods1.getName()))
                .sorted(Comparator.comparing(Goods::getPrice))
                .limit(3)
                .forEach(System.out::println);
    }

}
